package com.zx.dsptuneup_TriMic.Adapter;

import android.content.Context;
import android.util.SparseBooleanArray;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.zx.dsptuneup_TriMic.Base.BaseAdapter;
import com.zx.dsptuneup_TriMic.Data_Bean.MatrixVo;
import com.zx.dsptuneup_TriMic.Data_Bean.Strategy;
import com.zx.dsptuneup_TriMic.R;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;

public class StrategyAdapter extends BaseAdapter {
    private Context context;
    private List<Strategy> gridViewBeanList;

    private OnDbChangeListener onDbChangeListener;


    public List<Strategy> getGridViewBeanList() {
        return gridViewBeanList;
    }

    public void setOnDbChangeListener(OnDbChangeListener onDbChangeListener) {
        this.onDbChangeListener = onDbChangeListener;
    }

    public void setGridViewBeanList(List<Strategy> gridViewBeanList) {
        this.gridViewBeanList = gridViewBeanList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(context, R.layout.item_list_strategy,null));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        final ViewHolder viewHolder = (ViewHolder) holder;
        Strategy childDeviceBean = gridViewBeanList.get(position);
        viewHolder.strategy_name.setText(childDeviceBean.getName());
        viewHolder.start_txt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onDbChangeListener != null){
                    onDbChangeListener.DbChange(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return gridViewBeanList.size();
    }

    public StrategyAdapter(Context context, List<Strategy> gridViewBeanList) {
        super(context);
        this.context = context;
        this.gridViewBeanList = gridViewBeanList;
    }

    @Override
    public void notifyDataSetChanged(List dataList) {

    }

    public interface OnDbChangeListener {
        /**
         * 回调方法
         */
        void DbChange( int position);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.strategy_name)
        TextView strategy_name;

        @BindView(R.id.start_txt)
        TextView start_txt;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

    }
}
